<?php
/**
 * 单页信息
 * Created by PhpStorm.
 * User: ECHO
 * Time: 9:44
 */

namespace app\admin\controller;

use app\common\controller\AdminBase;

class Webrelationus extends AdminBase
{
    //首页
    public function index(){
        $nid = 4;
        $rows = db('pageinfo')->where(['nid'=>$nid])->find();
        if($this->request->isPost()){
            $data['nid'] = $nid;
            $data['content'] = json_encode($_POST['content'],JSON_UNESCAPED_UNICODE);
            $data['add_time'] = $_POST['add_time'];
            if($rows){
                if(db('pageinfo')->where(['id'=>$rows['id']])->update($data) !==false){
                    $this->success('更新成功');
                }else{
                    $this->error('更新失败');
                }
            }else{
                if(db('pageinfo')->insert($data) !== false){
                    $this->success('保存成功');
                }else{
                    $this->error('保存失败');
                }
            }
        }
        $rows['content'] = json_decode($rows['content'],true);
        return $this->fetch('index',['rows'=>$rows]);
    }
}